package com.dingwei.superiordiary.mvp.presenter;

import com.dingwei.superiordiary.base.MyBaseBean;
import com.dingwei.superiordiary.bean.CommunityNewsBean;
import com.dingwei.superiordiary.bean.FailsBean;
import com.dingwei.superiordiary.bean.IntegerMallBean;
import com.dingwei.superiordiary.custom.myCallback;
import com.dingwei.superiordiary.mvp.view.Contract;
import com.lihao.baselibrary.base.BaseActivity;
import com.lihao.baselibrary.base.URLS;
import com.lihao.baselibrary.base.basePresenter;

import org.xutils.http.RequestParams;
import org.xutils.x;

/**
 * Created by lihao on 2017/9/12.
 */

public class IntegerMallPresenter extends basePresenter {

    private Contract.IntegalMallView integalMallView;

    public IntegerMallPresenter(Contract.IntegalMallView view) {
        super(view);
        this.integalMallView = view;
    }


    public void initData(int page, final boolean isRefresh, boolean isShowDialog) {
        RequestParams rp = new RequestParams(URLS.HOST+URLS.GETINTEGRALLIST);
        rp.addBodyParameter("page",page+"");
        rp.addBodyParameter("sessionid", BaseActivity.value.getToken());


        x.http().post(rp, new myCallback(BaseActivity.context,IntegerMallBean.class,isShowDialog,rp) {
            @Override
            public void back(MyBaseBean baseBean, String result) {
                IntegerMallBean bean = (IntegerMallBean) baseBean;
                if (isRefresh){
                    integalMallView.onRefresh(bean);
                }else {
                    integalMallView.onLoadMore(bean);
                }
            }

            @Override
            public void fail(FailsBean baseBean, String result) {
                integalMallView.onFail();
            }
        });

    }

}
